﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Reflection;
using System.Linq.Expressions;

namespace LBCMS.Helper
{
    public class ReflectionHelper
    {

        /// <summary>
        /// 获取类的所有属性，排除导航属性
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="entity"></param>
        /// <returns></returns>
        public Dictionary<string, System.Type> getProperties<T>(T entity)
        {
            Dictionary<string, System.Type> proList = new Dictionary<string, Type>();
            Type tp = entity.GetType();
            PropertyInfo[] properties = tp.GetProperties(BindingFlags.Instance | BindingFlags.Public);
            foreach (PropertyInfo p in properties)
            {
                if (p.PropertyType.Name.IndexOf("ICollection") == 0)
                {
                    continue;
                }
                proList.Add(p.Name, p.PropertyType);
            }

            return proList;
        }
    }

}